#ifndef UILOADER_H
#define UILOADER_H

#include <gtkmm.h>
#include <ImageType.hpp>
#include <array>

class UILoader
{
  public:
    UILoader();
    virtual ~UILoader();

    Glib::RefPtr<Gtk::Builder> refBuilder;
    Glib::RefPtr<Gtk::CssProvider> cssProvider;

    Gtk::Window* mainWindow;
    Gtk::Grid* monitorGrid;
    Gtk::ColumnView* cameraList;
    Gtk::Label* labTmuxStatus;
    Gtk::Label* labRecordStatus;
    Gtk::Label* labTitle;
    Gtk::DrawingArea* imgLogo;

    void ShowOriginImage(const ImageType& data,int index);
    void SetMobileConnectStatus(bool);
    void SetRecordStatus(bool);

  private:
    bool MobileStatus=false;
    bool RecordStatus=false;
    class ModelColumns : public Glib::Object
    {
      public:
        Glib::ustring m_col_name;
        Glib::ustring m_col_id;
        Glib::ustring m_col_ip;
        static Glib::RefPtr<ModelColumns> create(Glib::ustring name,Glib::ustring id,Glib::ustring ip)
        {
          return Glib::make_refptr_for_instance<ModelColumns>(new  ModelColumns(name,id,ip));
        }
      protected:
        ModelColumns(Glib::ustring name,Glib::ustring id,Glib::ustring ip)
          : m_col_name(name)
          , m_col_id(id)
          , m_col_ip(ip)
        {}
    };
    template<class T> T* GetInstance(const char* name);
    std::array<Gtk::DrawingArea*,6> drawImage;
    std::array<Glib::RefPtr<Gdk::Pixbuf>,6> imageList;
    std::array<std::mutex,6> imageMutList;
    std::array<bool,6> imageUpdateFlag;
    Glib::Dispatcher m_dispatcher;
    Glib::RefPtr<Gio::ListStore<ModelColumns>> m_listStore;
    void on_setup_label(const Glib::RefPtr<Gtk::ListItem>& list_item);
    void on_bind_string(const Glib::RefPtr<Gtk::ListItem>& list_item,int index);
    void on_imgLogo_draw(const Cairo::RefPtr<Cairo::Context>& cr,int width,int height);
    
    void on_notification_from_work_thread();
    void on_draw(const Cairo::RefPtr<Cairo::Context>& cr,int width,int height,int index);
};

#endif
